package com.scaupos.mis11c.Service;

import com.scaupos.mis11c.Entities.ClothType;
import com.scaupos.mis11c.Repository.ClothTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ClothTypeServiceImp implements ClothTypeService {
    private final ClothTypeRepository clothTypeRepository;

    @Autowired
    ClothTypeServiceImp(ClothTypeRepository clothTypeRepository){
        this.clothTypeRepository = clothTypeRepository;
    }

    @Override
    public ClothType addClothType(ClothType clothType){
        return clothTypeRepository.save(clothType);
    }


    @Override
    public ClothType deleteClothType(Integer id) {
        ClothType deletedClothType = clothTypeRepository.findById(id).get();
        clothTypeRepository.deleteById(id);
        return deletedClothType;

    }

//    @Override
//    public List<ClothType> findAll() {
//        return clothTypeRepository.findById(new ObjectId(userId));
//    }

    @Override
    public ClothType findById(Integer id) {
        return clothTypeRepository.findById(id).get();
    }

    @Override
    public ClothType update(ClothType clothType) {
        clothTypeRepository.save(clothType);
        return clothType;
    }
}
